﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.Common;
using System.Linq.Expressions;

namespace Neotic.DataAccess.Sql.Operations
{
    public class Like : ISqlCondition
    {
        private ISelectColumn _leftColumn;
        private string _value;

        protected Like() {}

        public Like(ISelectColumn c, string val)
        {
            if (c == null)
                throw new ArgumentNullException("Paramètre c attendu");

            if (string.IsNullOrEmpty(val))
                throw new ArgumentNullException("Paramètre val attendu");

            _leftColumn = c;
            _value = val;
        }

        public virtual string ToSql(DbParameterCollection cmdParams)
        {
            string valuesPart = string.Empty;
            
            valuesPart = string.Concat("'%", _value, "%'");

            return string.Concat(_leftColumn.FullName, " LIKE (", valuesPart, ") ");
        }

        public ExpressionType? MyExpressionType { get { return null; } }

        public ISqlCondition ParseExpression(Expression<Func<ISqlCondition, object>> predicate)
        {
            throw new NotImplementedException();
        }
    }
}
